﻿using System;
using System.Collections.Generic;

namespace Microsoft.Popfly.GameCreator.GameEngine.Events
{
    public class DirectionChecker
    {
        private bool[] m_directions;

        public DirectionChecker(Dictionary<String, Data.CollisionDirectionInfo> directions)
        {
            m_directions = new bool[5];
            if (directions == null)
            {
                for (int i = 0; i < m_directions.Length; i++)
                {
                    m_directions[i] = true;
                }
            }
            else
            {
                foreach (var kvp in directions)
                {
                    int index = -1;
                    
                    switch (kvp.Value.Name)
                    {
                        case "top":
                            index = (int)CollisionDirectionArg.FilterDirections.FILTER_TOP;
                            break;
                        case "bottom":
                            index = (int)CollisionDirectionArg.FilterDirections.FILTER_BOTTOM;
                            break;
                        case "left":
                            index = (int)CollisionDirectionArg.FilterDirections.FILTER_LEFT;
                            break;
                        case "right":
                            index = (int)CollisionDirectionArg.FilterDirections.FILTER_RIGHT;
                            break;
                    }
                    m_directions[index] = kvp.Value.valid;
                }
            }
        }

        public bool CheckDirection(CollisionDirectionArg.FilterDirections filterDirection)
        {
            return m_directions[(int)filterDirection];
        }
    }
}
